package cn.edu.lnpu.manage.course.controller;

import cn.edu.lnpu.api.cource.CourseControllerApi;
import cn.edu.lnpu.common.model.response.QueryResponseResult;
import cn.edu.lnpu.common.model.response.ResponseResult;
import cn.edu.lnpu.domain.course.*;
import cn.edu.lnpu.domain.course.ext.CourseView;
import cn.edu.lnpu.domain.course.ext.TeachplanNode;
import cn.edu.lnpu.domain.course.response.CoursePublishResult;
import cn.edu.lnpu.manage.course.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/course")
public class CourseController implements CourseControllerApi {

    @Autowired
    CourseService courseService;

    @GetMapping("/coursebase/list/{page}/{size}")
    public QueryResponseResult<CourseBase> courseBaseList(@PathVariable("page") int page, @PathVariable("size") int size) {
        return courseService.courseBaseList(page,size);
    }

    @GetMapping("/coursebase/{courseId}")
    public CourseBase getCoursebaseById(@PathVariable("courseId") String courseId) {
        return courseService.findCourseBaseById(courseId);
    }

    @PostMapping("/courseMarket/update")
    public ResponseResult updateCourseMarketById (@RequestBody CourseMarket courseMarket) {
        courseService.updateCourseMarketById(courseMarket);
        return ResponseResult.SUCCESS();
    }

    @PostMapping("/coursebase/update")
    public ResponseResult updateCoursebaseById (@RequestBody CourseBase courseBase) {
        courseService.updateCoursebaseById(courseBase);
        return ResponseResult.SUCCESS();
    }

    @GetMapping("/courseMarket/{courseId}")
    public CourseMarket getCourseMarketById (@PathVariable("courseId") String courseId) {
        return courseService.getCourseMarketById(courseId);
    }


    @Override
    @GetMapping("/teachplan/list/{courseId}")
    public TeachplanNode findTeachplanList(@PathVariable("courseId") String courseId) {
        return courseService.findTeachplanList(courseId);
    }

    @Override
    @PostMapping("/teachplan/add")
    public ResponseResult addTeachplan(@RequestBody Teachplan teachplan) {
        return courseService.addTeachplan(teachplan);
    }

    @Override
    @PostMapping("/coursepic/add")
    public ResponseResult addCoursePic(@RequestParam("courseId") String courseId, @RequestParam("pic")String pic) {
        return courseService.addCoursePic(courseId,pic);
    }

    @Override
    @GetMapping("/coursepic/list/{courseId}")
    public CoursePic findCoursePic(@PathVariable("courseId") String courseId) {
        return courseService.findCoursePic(courseId);
    }

    @Override
    @DeleteMapping("/coursepic/delete")
    public ResponseResult deleteCoursePic(@RequestParam("courseId") String courseId) {
        return courseService.deleteCoursePic(courseId);
    }

    @Override
    @GetMapping("/courseview/{id}")
    public CourseView courseview(@PathVariable("id") String id) {
        return courseService.getCoruseView(id);
    }

    @Override
    @PostMapping("/preview/{id}")
    public CoursePublishResult preview(@PathVariable("id") String id) {
        return courseService.preview(id);
    }

    @Override
    @PostMapping("/publish/{id}")
    public CoursePublishResult publish(@PathVariable("id")String id) {
        return courseService.publish(id);
    }

    @Override
    @PostMapping("/savemedia")
    public ResponseResult savemedia(@RequestBody TeachplanMedia teachplanMedia) {
        return courseService.savemedia(teachplanMedia);
    }


}
